package logic

import (
	"context"
	"hui-hui/api/internal/svc"
	"hui-hui/api/internal/types"
	"hui-hui/hui_hui_rpc/huihuirpcclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserDataLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateUserDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserDataLogic {
	return &UpdateUserDataLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateUserDataLogic) UpdateUserData(req *types.UpdateUserDataRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	data, err := l.svcCtx.HuiHuiRoc.UpdateUserData(l.ctx, &huihuirpcclient.UpdateUserDataRequest{
		Id:    req.UserId,
		Name:  req.Name,
		Image: req.Image,
		Des:   req.Des,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "个人信息修改成功",
		Data:    data,
	}, nil
}
